<?php

require_once 'SQLHelper.class.php';

//该类是一个业务逻辑处理类，主要完成catalogs表的操作
class CatalogService{
		
	public function navigation(){
		 
		$sqlHelper = new SQLHelper();
		$sql = "select * from catalogs";
		$arr = $sqlHelper->execute_dql($sql);
		$sqlHelper->close_connect();

		$all = array();
		for($i=0;$i<count($arr);$i++){
			$row = $arr[$i];
			$cid = $row['cid'];
			$all[] = "<li><a href=blogManage.php?list=$cid>{$row['catalog']}</a></li>";
		}
			
		$navi = implode($all);
		return  $navi;
	}


	//这是一个在博文下面，给博文分类的方法
	public function addBlogNavi(){
		
		$sql = "select * from catalogs ";
		$sqlHelper = new SQLHelper();
		$arr = $sqlHelper->execute_dql($sql);
		$sqlHelper->close_connect();
		for($i=0;$i<count($arr);$i++){
			$row = $arr[$i];
                	$all[] = "<option value={$row['cid']}>{$row['catalog']}</option>";
		}

		$arr = implode($all);
		return $arr;

	}

	//这是一个提取出所有目录名的类,以便changConfig修改它的值
	public function getCatalog(){
		$sql = "select catalog from catalogs";
		$sqlHelper = new SQLHelper();
		$arr = $sqlHelper->execute_dql($sql);
		$sqlHelper->close_connect();
		return $arr;
	}

	//修改导航栏的名字
	public function changeConfig($catalog){
		
		$sqlHelper = new SQLHelper();
		for($i=0;$i<count($catalog);$i++){
			$sql = "update catalogs set catalog='$catalog[$i]' where cid = $i+1";
			$sqlHelper->execute_dml($sql);
			
		}
		$sqlHelper->close_connect();
	}
}

?>
